﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CGT.GOP.Common
{
    /// <summary>
    /// 返回结果实体
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ResultData<T>
    {
        //: IHttpActionResult
        /// <summary>
        /// 错误信息
        /// </summary>
        public string message { set; get; }

        /// <summary>
        /// 返回状态
        /// 0：成功,否则失败
        /// </summary>
        public int status { set; get; }

        /// <summary>
        /// 返回信息
        /// </summary>
        public T data { set; get; }

        /// <summary>
        /// 成功方法
        /// </summary>
        /// <param name="_data">返回对象</param>
        /// <returns></returns>
        public static ResultData<T> Success(T _data)
        {
            ResultData<T> result = new ResultData<T>
            {
                status = 0,
                message = string.Empty,
                data = _data
            };
            return result;
        }

        /// <summary>
        /// 成功方法
        /// </summary>
        /// <param name="_data">返回数据</param>
        /// <param name="msg">返回成功文本</param>
        /// <returns></returns>
        public static ResultData<T> Success(T _data, string msg)
        {
            ResultData<T> result = new ResultData<T>
            {
                status = 0,
                message = msg,
                data = _data
            };
            return result;
        }

        /// <summary>
        /// 成功
        /// </summary>
        /// <returns></returns>
        public static ResultData<T> Success()
        {
            ResultData<T> result = new ResultData<T>
            {
                status = 0,
            };
            return result;
        }
        /// <summary>
        /// 失败方法
        /// </summary>
        /// <param name="errMsg">错误信息</param>
        /// <returns></returns>
        public static ResultData<T> Error(string errMsg)
        {
            ResultData<T> result = new ResultData<T>
            {
                status = -1,
                message = errMsg
            };
            return result;
        }
    }

    /// <summary>
    /// 返回主体分页
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ResultPageData<T> : ResultData<T>
    {
        /// <summary>
        /// 总数
        /// </summary>
        public long total { set; get; }
    }
}